package com.autumn.zero.authorization.entitys.users;

import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.autumn.constants.SettingConstants;
import com.autumn.mybatis.mapper.annotation.ColumnOrder;
import com.autumn.mybatis.mapper.annotation.Index;
import com.autumn.mybatis.mapper.annotation.TableEngine;
import com.autumn.util.ExceptionUtils;
import com.autumn.zero.authorization.constants.LoginResultConstants;

/**
 * 用户登录尝试
 * 
 * @author 杨昌国 2018-11-29 22:11:22
 */
@Table(name = SettingConstants.SYS_TABLE_PREFIX + "_user_login_attempt")
@TableEngine("MyISAM")
public class UserLoginAttempt extends UserLoginLog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1335369930087629760L;

	/**
	 * 字段 loginResult
	 */
	public static final String FILED_LOGIN_RESULT = "loginResult";

	/**
	 * {@link com.autumn.zero.authorization.constants.LoginResultConstants}
	 */
	@NotNull(message = "登录结果不能为空")
	@Index(unique = false)
	@ColumnOrder(100)
	private Integer loginResult;

	/**
	 * 获取登录结果
	 * 
	 * @return {@link com.autumn.zero.authorization.constants.LoginResultConstants}
	 */
	public Integer getLoginResult() {
		return loginResult;
	}

	/**
	 * 设置登录结果
	 * 
	 * @param loginResult {@link com.autumn.zero.authorization.constants.LoginResultConstants}
	 */
	public void setLoginResult(Integer loginResult) {
		this.loginResult = loginResult;
	}

	@Override
	public void valid() {
		super.valid();
		if (!LoginResultConstants.exist(this.getLoginResult())) {
			ExceptionUtils.throwValidationException("无效的用户登录状态。");
		}
	}
}
